<?php
namespace app\home\controller\agent;
use app\home\controller\Base;

class Handle extends Base
{
	private $params;
	public function __construct(){
		parent::__construct();
		if(!session('member.is_agent')){
			$this->error('权限不足');
		}
		// token验证
		if(false == Base::checkToken()){
			$this->error('token error!');
		}
		// 参数去token
		$params = $this -> request -> post();
		unset($params['token']);
		$this->params = $params;
	}

	public function register(){
		$memberData = $this->params;
		$memberData['agent_id'] = MID;
    	
    	$result = $this->validate($memberData, 'Member.agent_add');
    	if(true !== $result) {
    	    $this->error($result);
        }
        
        $model = model('member');
        $result = $model->addMember($memberData);

        if(false === $result) {
            $this->error($model->getError());
        }
        if(true===$result){
            $this->success('空单会员添加成功');
        }
        $scoreId = $result;

        $this->success('添加成功',null,['callback'=>url('bonus.api/deal_bonus'),'operate_id'=>$scoreId]);
	}

}